package day01;

import java.util.Scanner;

/**
 * Created by MGL on 2017/4/2.
 */

public class Test03 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int[] arr = new int[count];
        for (int i = 0; i < count; i++) {
            arr[i] = sc.nextInt();
        }
        test(arr, 0);
    }

    private static void test(int[] arr, int count) {
        arr[0] = arr[0] / 2;
        int temp = arr[0];
        for (int i = 0; i < arr.length - 1; i++) {
            arr[i] = arr[i] + arr[i + 1] / 2;
            arr[i + 1] = arr[i + 1] / 2;
            if (arr[i] % 2 != 0) {
                arr[i]++;
                count++;
            }
        }
        if ((arr[arr.length - 1] = arr[arr.length - 1] + temp) % 2 != 0) {
            arr[arr.length - 1]++;
            count++;
        }
        if (isEquals(arr)) {
            System.out.println(count);
            return;
        } else {
            test(arr, count);
        }
    }

    private static boolean isEquals(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] != arr[i + 1]) {
                return false;
            }
        }
        return true;
    }

}